package zj.com.fragments;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import zj.com.activities.DshDetailEditActivity;
import zj.com.adapter.DzgSpAdapter;
import zj.com.app.ZjApplication;
import zj.com.model.AuditLog;
import zj.com.model.RecordDetail;
import zj.com.net.NetManager;
import zj.com.net.OnResponseListener;
import zj.com.util.LogUtils;
import zj.com.zj.R;

/**
 * Created by xi on 16/6/4.
 * 待审核 审批
 */
public class DshDetailSpFragment extends Fragment {


    public ListView listView;
    public List<AuditLog> list;
    public Intent intent;

    public DzgSpAdapter adapter;
    public View error_rl;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_dzg_detail_sp, container, false);
        initView(view);
        initData();
        return view;
    }
    public void initView(View view){
        error_rl =view.findViewById(R.id.error_rl);

        listView = (ListView) view.findViewById(R.id.listView);
    }

    public void initData(){
        list = new ArrayList<AuditLog>();
        adapter = new DzgSpAdapter(list,getActivity());
        listView.setAdapter(adapter);


    }

    @Override
    public void onResume() {
        super.onResume();
        obtainData();
        LogUtils.getInstance().error(" ======DshDetailSpFragment  on resume ");
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if(isVisibleToUser){
            List<AuditLog> list =  ZjApplication.auditLogList;
            if(list != null && list.size() > 0){

                adapter.setDataChange(list);
                error_rl.setVisibility(View.GONE);

            }else{
                error_rl.setVisibility(View.VISIBLE);
            }
        }
    }

    public void obtainData(){


       List<AuditLog> list =  ZjApplication.auditLogList;
       if(list != null){
           LogUtils.getInstance().error(" ======AuditLog size  on resume "+list.size());

           adapter.setDataChange(list);
       }
    }
}
